﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using iTeachSoft.Presentation.Dialogs;
using Microsoft.Win32;
using iTeachSoft.Code.Utility;
using System.Windows;
using iTeachSoft.CoreObjects;
using System.Windows.Forms;
using iTeachSoft.Presentation.Code.Managers;
using iTeachSoft.CoreObjects.Recording;
using System.Drawing;

namespace iTeachSoft.Code.Managers
{
    public class ActionsManager
    {
        public static void NewProject()
        {
            if (RuntimeStorage.CurrentProject != null)
            {
                MessageBoxResult userResult = AlertUtility.Confirm("Would you like to save the current project?");
                if (userResult == MessageBoxResult.Cancel)
                    return;

                if (userResult == MessageBoxResult.Yes)
                    SaveCurrentProject();
            }

            DialogNewProject newProjectDlg = new DialogNewProject();
            newProjectDlg.Show();
        }

        public static void SaveCurrentProject()
        {
            //TODO
        }

        public static void LoadProject()
        {
            //TODO open a file dialog and load the selected project
        }

        public static void ShowSlideProperties(Slide slide)
        {
            DialogSlideProperties dlgProperties = new DialogSlideProperties(slide);
            dlgProperties.Show();
        }

        public static void ExportPresentationAsAVI()
        {
            DialogExportAsAvi dlgExport = new DialogExportAsAvi();
            dlgExport.Show();
        }

        public static void ShowProjectOptions()
        {
            DialogNewProject dlgProject = new DialogNewProject();
            dlgProject.Show();
        }

        public static void StartRecording()
        {
            DialogRecordingOptions dlgRecord = new DialogRecordingOptions(RuntimeStorage.CurrentRecordSettings);
            if (dlgRecord.ShowDialog().Value == true)
            {
                System.Windows.Application.Current.MainWindow.WindowState = WindowState.Minimized;
            }
        }

        #region "Insert stuff"

        public static void InsertNewFrame()
        {
            DialogInsertFrame dlgInsertFrame = new DialogInsertFrame();
            dlgInsertFrame.Show();
        }

        public static void InsertAnnotation()
        {
            RuntimeStorage.ToBeInsertedObject = new Annotation();
        }

        public static void InsertTextAnnotation()
        {
            RuntimeStorage.ToBeInsertedObject = new RectangleWithText();
        }

        public static void InsertAudioTrack(Slide slide)
        {
            DialogInsertAudioTrack dlgAudioTrack = new DialogInsertAudioTrack(slide);
            dlgAudioTrack.Show();
        }

        #endregion

        #region "Edit actions"

        public static void CutSelectedShape()
        {
            //TODO
        }

        public static void CopySelectedShape()
        {
            //TODO
        }

        public static void PasteSelectedShape()
        {
            //TODO
        }

        public static void DeleteSlide(Slide slide)
        {
            RuntimeStorage.CurrentProject.Slides.Remove(slide);
            EventsManagement.Instance.OnReflectProjectInvoked(null, EventArgs.Empty);
        }

        public static void DeleteCoreObject(Slide slide, BaseSlideObject slideObject)
        {
            slide.SlideObjects.Remove(slideObject);

            EventsManagement.Instance.OnReflectProjectInvoked(null, EventArgs.Empty);
        }

        #endregion

        public static void ShowCoreObjectProperties(BaseSlideObject slideObject)
        {
            
        }


        internal static void StopRecording()
        {
            Bitmap[] images = RecordingManager.EndRecording();
            EventsManagement.Instance.OnRecordingEnded(null, new iTeachSoft.Presentation.Code.Utility.SingleItemEventArgs<Bitmap[]>(images));
        }
    }
}
